* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Arial', sans-serif;
}

body {
    background-color: #f5f5f5;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
    height: 100vh; /* 使用视口高度 */
    width: 100%;
    overflow: hidden; /* 防止滚动 */
}

.container {
    max-width: 1200px;
    width: 100%;
    height: 100%; /* 填充整个高度 */
    background-color: white;
    border-radius: 10px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
    padding: 10px;
    display: flex;
    flex-direction: row;
    align-items: stretch;
    overflow: hidden; /* 防止内部内容溢出 */
}

/* 左侧控制区域 - 全局优化 */
.control-sidebar {
    width: 220px; /* 更紧凑的宽度 */
    flex-shrink: 0;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: hidden; /* 防止滚动 */
    border-right: 1px solid #f0f0f0;
}

/* 右侧游戏区域 */
.game-area {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 0;
    width: 100%; /* 确保占据所有可用宽度 */
    height: 100%; /* 确保占据所有可用高度 */
}

.game-area::before {
    content: '点击' 开始游戏 '按钮开始';
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    width: 100%;
    height: 100%;
    font-size: 16px;
    color: #666;
    text-align: center;
    z-index: 1;
}

.game-active .game-area::before {
    display: none;
}

h1 {
    color: #333;
    margin-bottom: 10px;
    text-align: center;
    font-size: 20px; /* 减小标题大小 */
    line-height: 1.2;
}

/* 游戏信息区域全局优化 */
.game-info {
    display: flex;
    flex-direction: column;
    width: 100%;
    gap: 8px;
    margin-bottom: 5px;
}

/* 当前寻找数字的文本样式 */
.current-number {
    font-weight: bold;
    padding: 8px 10px;
    background-color: #e3f2fd;
    border-radius: 5px;
    border-left: 4px solid #1976d2;
    display: flex;
    align-items: center;
    width: 100%;
}

#current-number {
    color: #0d47a1;
    font-size: 20px;
    font-weight: 900;
    margin-left: 5px;
}

/* 添加时间和关卡信息的样式 */
.timer {
    display: flex !important;
    align-items: center;
    gap: 5px;
    background-color: rgba(0, 180, 180, 0.1);
    border: 1px solid #00b4b4;
    color: #00b4b4;
    font-weight: bold;
    padding: 8px 10px;
    border-radius: 5px;
}

/* 关卡信息行样式 */
.level-info {
    border-left: 4px solid #4caf50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
}

/* 信息按钮样式 */
.info-btn {
    background-color: #9c27b0;
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
    margin-left: 5px;
    flex-shrink: 0;
}

.info-btn:hover {
    transform: scale(1.1);
    background-color: #7b1fa2;
}

#time-limit-bar-container {
    display: block !important;
    width: 100%;
    background-color: #e0e0e0;
    height: 8px;
    border-radius: 4px;
    overflow: hidden;
    margin-top: 5px;
    z-index: 10;
    position: relative;
}

#time-limit-bar {
    height: 100%;
    width: 100%;
    background-color: #00b4b4;
    transition: width 0.1s linear;
}

#time-limit-bar.time-warning {
    background-color: #ff9800;
}

#time-limit-bar.time-danger {
    background-color: #f44336;
}

/* 控制区域全局优化 */
.controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    margin: 5px 0;
}

.level-selector {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    width: 100%;
}

.level-selector label {
    font-size: 13px;
    font-weight: 500;
    color: #555;
    margin-bottom: 0;
}

.level-selector select {
    width: 100%;
    padding: 6px 8px;
    border-radius: 6px;
    border: 1px solid #ddd;
    background-color: #f9f9f9;
    font-size: 13px;
}

button {
    background-color: #4caf50;
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    transition:
        background-color 0.3s,
        transform 0.2s;
    width: 100%;
}

button:hover {
    background-color: #45a049;
    transform: translateY(-2px);
}

#next-level-btn {
    background-color: #2196f3;
}

#next-level-btn:hover {
    background-color: #0b7dda;
}

/* 关卡描述全局优化 */
.level-description {
    margin-top: 12px;
    padding: 15px;
    background-color: #f9f9f9;
    border-radius: 8px;
    border-left: 4px solid #9c27b0;
    width: 100%;
    font-size: 13px;
    line-height: 1.6;
    max-height: 220px;
    overflow-y: auto;
}

.level-description h3 {
    margin-bottom: 8px;
    color: #9c27b0;
    font-size: 16px;
}

.level-description p {
    margin-bottom: 5px;
}

/* 关卡描述中的特殊样式 */
.record-info {
    background-color: rgba(76, 175, 80, 0.1);
    padding: 5px 8px;
    border-radius: 4px;
    display: block;
    margin: 8px 0;
    color: #2e7d32;
    font-weight: 600;
}

.star-req {
    color: #7b1fa2;
    font-weight: 600;
    display: block;
    margin: 8px 0 4px 0;
    border-bottom: 1px dotted rgba(123, 31, 162, 0.3);
    padding-bottom: 3px;
}

/* 警告文本的样式 */
.level-description strong[style*='color:#f44336'] {
    background-color: rgba(244, 67, 54, 0.1);
    padding: 3px 6px;
    border-radius: 4px;
    display: inline-block;
    margin: 4px 0;
}

/* 通用网格容器优化 */
.grid-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    width: 90%; /* 稍微减少宽度以留出一些边距 */
    max-width: min(90vw, 90vh); /* 使用视口宽度和高度的最小值 */
    aspect-ratio: 1/1; /* 保持网格为正方形 */
    margin: 0 auto; /* 居中 */
    align-self: center; /* 在flex容器中居中 */
    justify-self: center; /* 在grid容器中居中 */
}

.grid-item {
    background-color: #fff;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    aspect-ratio: 1/1;
    min-height: 0; /* 移除最小高度限制，让它完全基于容器尺寸 */
    font-size: clamp(18px, 5vw, 36px); /* 响应式字体大小基准 */
}

/* 精细调整大网格的交互效果 */
.grid-container[style*='repeat(6, 1fr)'] .grid-item,
.grid-container[style*='repeat(7, 1fr)'] .grid-item {
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    border-width: 1px;
}

.grid-item:hover {
    background-color: #e9e9e9;
    transform: scale(1.05);
    z-index: 1; /* 确保悬停项显示在其他项之上 */
}

/* 针对大网格调整悬停缩放效果，避免重叠 */
.grid-container[style*='repeat(5, 1fr)'] .grid-item:hover,
.grid-container[style*='repeat(6, 1fr)'] .grid-item:hover,
.grid-container[style*='repeat(7, 1fr)'] .grid-item:hover {
    transform: scale(1.03);
}

/* 在小屏幕上进一步减少悬停效果，避免重叠 */
@media (max-width: 600px) {
    .grid-item:hover {
        transform: scale(1.03);
    }

    .grid-container[style*='repeat(5, 1fr)'] .grid-item:hover,
    .grid-container[style*='repeat(6, 1fr)'] .grid-item:hover,
    .grid-container[style*='repeat(7, 1fr)'] .grid-item:hover {
        transform: scale(1.01);
    }
}

/* 当前寻找数字的突出显示样式 */
.grid-item.current-target {
    background-color: #e3f2fd;
    color: #0d47a1;
    border: 2px solid #1976d2;
    box-shadow: 0 0 8px rgba(25, 118, 210, 0.5);
    transform: scale(1.05);
    font-weight: 900;
    z-index: 2;
}

.grid-item.correct {
    background-color: #d4edda;
    color: #155724;
}

.grid-item.wrong {
    background-color: #f8d7da;
    color: #721c24;
    animation: shake 0.5s;
}

/* 颜色干扰模式的样式 */
.grid-item.color-distraction {
    color: transparent;
    text-shadow: 0 0 0 #333;
    background-image: linear-gradient(45deg, rgba(255, 0, 0, 0.2), rgba(0, 255, 0, 0.2), rgba(0, 0, 255, 0.2));
    background-size: 200% 200%;
    animation: gradient-shift 3s ease infinite;
}

@keyframes gradient-shift {
    0% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
    100% {
        background-position: 0% 50%;
    }
}

/* 移动挑战模式的样式 */
.grid-item.moving {
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0% {
        transform: translateY(0px);
    }
    50% {
        transform: translateY(-5px);
    }
    100% {
        transform: translateY(0px);
    }
}

@keyframes shake {
    0% {
        transform: translateX(0);
    }
    25% {
        transform: translateX(-5px);
    }
    50% {
        transform: translateX(5px);
    }
    75% {
        transform: translateX(-5px);
    }
    100% {
        transform: translateX(0);
    }
}

/* 定义整个网格的震动动画，用于错误次数过多时 */
@keyframes shake-grid {
    0% {
        transform: translateX(0);
    }
    10% {
        transform: translateX(-10px);
    }
    20% {
        transform: translateX(10px);
    }
    30% {
        transform: translateX(-10px);
    }
    40% {
        transform: translateX(10px);
    }
    50% {
        transform: translateX(-10px);
    }
    60% {
        transform: translateX(10px);
    }
    70% {
        transform: translateX(-10px);
    }
    80% {
        transform: translateX(10px);
    }
    90% {
        transform: translateX(-10px);
    }
    100% {
        transform: translateX(0);
    }
}

.shake-effect {
    animation: shake-grid 0.8s ease;
}

.hidden {
    display: none !important;
}

/* 蒙层样式 */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 1000;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.result-modal {
    background-color: white;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    max-width: 500px;
    width: 90%;
    transform: scale(0.9);
    transition: transform 0.3s ease;
    box-shadow: 0 5px 30px rgba(0, 0, 0, 0.3);
}

.modal-overlay.active .result-modal {
    transform: scale(1);
}

.result-modal h2 {
    color: #2e7d32;
    font-size: 32px;
    margin-bottom: 15px;
}

.result-modal p {
    font-size: 20px;
    margin-bottom: 20px;
}

#final-time {
    font-weight: bold;
    font-size: 24px;
    color: #0d47a1;
}

/* 星级显示样式 */
.stars-container {
    display: flex;
    justify-content: center;
    margin: 20px 0;
    gap: 15px;
}

.star {
    font-size: 40px; /* 增大星星大小 */
    color: #ccc;
    transition: all 0.3s ease;
}

.star.active {
    color: #ffd700;
    animation: star-pulse 0.5s ease-in-out;
}

@keyframes star-pulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.3);
    }
    100% {
        transform: scale(1);
    }
}

/* 添加脉动动画样式 */
@keyframes pulse-animation {
    0% {
        transform: scale(1.05);
        box-shadow: 0 4px 8px rgba(33, 150, 243, 0.3);
    }
    50% {
        transform: scale(1.12);
        box-shadow: 0 6px 12px rgba(33, 150, 243, 0.5);
    }
    100% {
        transform: scale(1.05);
        box-shadow: 0 4px 8px rgba(33, 150, 243, 0.3);
    }
}

.pulse-animation {
    animation: pulse-animation 1.5s infinite ease-in-out;
}

/* 添加按钮容器的样式 */
#level-complete-message {
    margin-bottom: 15px;
}

#next-level-status {
    font-weight: bold;
}

/* 将按钮排成一行 */
.result-buttons {
    display: flex;
    justify-content: space-between;
    gap: 15px;
    margin-top: 15px;
}

/* 为蒙层中的下一关卡状态文本添加强调样式 */
#modal-level-status {
    font-weight: bold;
    color: #1565c0;
    font-size: 1.1em;
    margin: 10px 0;
    display: block;
}

/* 为蒙层中的"下一关卡"按钮设置蓝色样式 */
#modal-next-btn {
    background-color: #2196f3;
    font-size: 20px;
    padding: 14px 24px;
    box-shadow: 0 4px 8px rgba(33, 150, 243, 0.3);
    transform: scale(1.05);
    order: 2;
    border-radius: 8px;
    font-weight: bold;
    letter-spacing: 0.5px;
    position: relative;
    overflow: hidden;
}

#modal-next-btn::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        120deg,
        rgba(255, 255, 255, 0) 30%,
        rgba(255, 255, 255, 0.2),
        rgba(255, 255, 255, 0) 70%
    );
    transform: translateX(-100%);
}

#modal-next-btn.pulse-animation::after {
    animation: btn-shine 2s infinite;
}

@keyframes btn-shine {
    100% {
        transform: translateX(100%);
    }
}

#modal-next-btn:hover {
    background-color: #0b7dda;
    transform: scale(1.1);
    transition: all 0.3s ease;
}

/* 为重新开始按钮设置样式 */
#modal-restart-btn {
    order: 1;
}

/* 横屏特定的媒体查询 */
@media (max-height: 450px) and (orientation: landscape) {
    body {
        padding: 3px;
    }

    .container {
        padding: 5px;
    }

    .control-sidebar {
        width: 170px; /* 进一步减小宽度 */
        padding: 5px;
        gap: 3px;
    }

    h1 {
        font-size: 16px;
        margin-bottom: 3px;
    }

    .game-info {
        gap: 3px;
    }

    .current-number,
    .timer,
    .level-info {
        padding: 3px 5px;
        font-size: 11px;
    }

    #current-number {
        font-size: 14px;
    }

    .controls {
        gap: 3px;
        margin: 3px 0;
    }

    button {
        padding: 4px 7px;
        font-size: 11px;
    }

    .level-selector {
        gap: 1px;
    }

    .level-selector label {
        font-size: 10px;
        margin-bottom: 0;
    }

    .level-selector select {
        padding: 3px 5px;
        font-size: 10px;
    }

    #time-limit-bar-container {
        height: 4px;
        margin: 2px 0;
    }
}

/* 特定于iPhone横屏的优化 */
@media only screen and (min-device-width: 375px) and (max-device-width: 926px) and (orientation: landscape) {
    body {
        padding: 2px;
    }

    .container {
        padding: 5px;
        height: 99vh;
    }

    .control-sidebar {
        width: 160px;
        padding: 8px;
        gap: 4px;
    }

    .game-area {
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0;
        flex-grow: 1;
        height: 100%;
    }

    .grid-container {
        width: 95%;
        max-width: 85vh; /* 使用视口高度的85%作为最大宽度 */
        gap: 3px;
        margin: 0 auto;
    }

    h1 {
        font-size: 16px;
        margin-bottom: 3px;
    }

    .game-info {
        gap: 3px;
    }

    .current-number,
    .timer,
    .level-info {
        padding: 3px 5px;
        font-size: 11px;
    }

    #current-number {
        font-size: 14px;
    }

    .level-selector label,
    .level-selector select,
    button {
        font-size: 11px;
        padding: 3px 6px;
    }

    .level-description {
        padding: 3px 5px;
        margin-top: 3px;
        font-size: 10px;
        max-height: 110px;
        overflow-y: auto;
    }

    .level-description h3 {
        font-size: 11px;
        margin-bottom: 2px;
    }

    .level-description p {
        font-size: 10px;
        line-height: 1.1;
        margin-bottom: 2px;
    }

    /* 确保关卡说明中的警告文字不会被截断 */
    .level-description strong {
        display: inline-block;
    }
}

/* 响应式设计调整 - 竖屏模式，通用优化 */
@media (max-width: 900px) and (orientation: portrait) {
    body {
        padding: 10px;
    }

    .container {
        flex-direction: column;
        height: auto;
        max-height: none;
        width: 100%;
        padding: 15px;
    }

    .control-sidebar {
        width: 100%;
        padding: 15px;
        margin-bottom: 15px;
        max-height: none;
        border-right: none;
        border-bottom: 1px solid #f0f0f0;
    }

    .game-info {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 8px;
        justify-content: space-between;
    }

    .current-number,
    .timer,
    .level-info {
        flex: 1;
        min-width: 100px;
    }

    .controls {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 10px;
        margin-bottom: 10px;
    }

    .level-selector {
        flex: 3;
    }

    button#start-btn {
        flex: 2;
    }

    .game-area {
        width: 100%;
        flex-grow: 1;
        padding: 15px 0;
        min-height: 50vh; /* 确保游戏区域至少占屏幕高度的一半 */
        background-color: #f9f9f9;
        border-radius: 8px;
        border: 1px solid #eee;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .grid-container {
        max-width: 95%; /* 竖屏模式下几乎填满所有宽度 */
        width: 95%;
        aspect-ratio: 1/1;
        margin: 0 auto;
    }

    /* 针对不同网格大小优化间距 */
    .grid-container[style*='repeat(4, 1fr)'] {
        gap: 6px;
    }

    .grid-container[style*='repeat(5, 1fr)'] {
        gap: 5px;
    }

    .grid-container[style*='repeat(6, 1fr)'],
    .grid-container[style*='repeat(7, 1fr)'] {
        gap: 4px;
    }
}

/* 小屏设备优化（手机等） */
@media (max-width: 600px) {
    body {
        padding: 5px;
    }

    .container {
        padding: 10px;
    }

    h1 {
        font-size: 18px;
        margin-bottom: 10px;
    }

    .game-info {
        gap: 5px;
    }

    .current-number,
    .timer,
    .level-info {
        padding: 8px 10px;
        font-size: 12px;
    }

    #current-number {
        font-size: 16px;
    }

    .controls {
        gap: 5px;
        margin-bottom: 8px;
    }

    button {
        padding: 8px 10px;
        font-size: 13px;
    }

    .level-selector label {
        font-size: 12px;
    }

    .level-selector select {
        padding: 6px 8px;
        font-size: 12px;
    }

    .level-description {
        padding: 10px;
        font-size: 12px;
        line-height: 1.4;
        max-height: 180px;
    }

    .level-description h3 {
        font-size: 14px;
        margin-bottom: 5px;
    }

    .grid-item {
        font-size: 18px;
        min-height: 40px;
    }

    .game-area {
        min-height: 60vh; /* 增加游戏区域高度，为网格提供更多空间 */
        padding: 8px 0;
    }

    .grid-container {
        width: 98%; /* 几乎占满所有宽度 */
        max-width: 98%;
        gap: 6px;
    }

    /* 较大网格的间距更小 */
    .grid-container[style*='repeat(5, 1fr)'],
    .grid-container[style*='repeat(6, 1fr)'],
    .grid-container[style*='repeat(7, 1fr)'] {
        gap: 3px;
    }
}

/* 横屏通用优化 */
@media (orientation: landscape) and (max-height: 500px) {
    body {
        padding: 5px;
    }

    .container {
        padding: 8px;
    }

    .control-sidebar {
        width: 200px;
        padding: 10px;
        gap: 8px;
    }

    h1 {
        font-size: 18px;
        margin-bottom: 8px;
    }

    .game-info {
        gap: 5px;
    }

    .current-number,
    .timer,
    .level-info {
        padding: 6px 8px;
        font-size: 12px;
    }

    .controls {
        gap: 5px;
        margin: 5px 0;
    }

    button {
        padding: 6px 10px;
        font-size: 13px;
    }

    .level-description {
        padding: 8px;
        margin-top: 5px;
        max-height: 150px;
        font-size: 11px;
        line-height: 1.3;
    }

    .level-description h3 {
        font-size: 13px;
        margin-bottom: 4px;
    }

    .grid-container {
        max-width: 80vh; /* 使用视口高度的80%作为最大宽度 */
        width: 90%;
        height: 90%; /* 确保在低高度横屏设备上也能填满 */
        gap: 5px; /* 减小间隙以容纳更多元素 */
    }

    .grid-item {
        font-size: 16px;
        border-width: 1px;
    }
}

/* 为一些特定尺寸的网格设置不同的样式 */
@media (min-width: 900px) {
    .grid-container {
        max-width: 85%; /* 在大屏幕上稍微缩小以保持美观 */
    }
}

@media (min-width: 1200px) {
    .grid-container {
        max-width: 80%; /* 在超大屏幕上进一步缩小以保持美观 */
    }
}

/* 为不同尺寸的网格设置字体和间距 */
.grid-container[style*='repeat(3, 1fr)'] .grid-item {
    font-size: min(8vw, 8vh, 40px);
}

.grid-container[style*='repeat(4, 1fr)'] .grid-item {
    font-size: min(6vw, 6vh, 32px);
}

.grid-container[style*='repeat(5, 1fr)'] .grid-item {
    font-size: min(5vw, 5vh, 28px);
}

.grid-container[style*='repeat(6, 1fr)'] .grid-item {
    font-size: min(4vw, 4vh, 24px);
}

.grid-container[style*='repeat(7, 1fr)'] .grid-item {
    font-size: min(3vw, 3vh, 20px);
}

/* 使游戏区域在游戏开始后占据更多空间 */
.game-active .game-area {
    padding: 0;
    max-width: 100%;
    max-height: 100%;
}

/* 使网格容器在游戏活动时占据更多空间 */
.game-active .grid-container {
    margin: 0 auto;
    max-width: min(95vw, 95vh); /* 使用视口宽度和高度的较小值 */
    width: 95%;
}

/* 为小尺寸设备调整网格间距 */
@media (max-width: 600px) {
    .grid-container {
        gap: 8px;
    }

    .grid-container[style*='repeat(5, 1fr)'],
    .grid-container[style*='repeat(6, 1fr)'],
    .grid-container[style*='repeat(7, 1fr)'] {
        gap: 4px;
    }

    .grid-item {
        border-width: 1px;
        border-radius: 6px;
    }
}

/* 为超大屏幕设置最大网格尺寸，避免网格过大导致不美观 */
@media (min-width: 1400px) {
    .grid-container {
        max-width: 800px;
    }
}

/* 横屏特定的媒体查询 */
@media (orientation: landscape) {
    .container {
        flex-direction: row;
    }

    .control-sidebar {
        width: 220px;
        max-width: 25%; /* 最多占据25%的容器宽度 */
    }

    .game-area {
        flex-grow: 1;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .grid-container {
        max-width: min(90%, min(90vh, 90vw - 250px)); /* 考虑左侧边栏的空间 */
        height: auto;
    }

    /* 游戏激活时 */
    .game-active .grid-container {
        max-width: min(95%, min(95vh, 95vw - 250px));
    }
}

/* 竖屏特定的媒体查询 */
@media (orientation: portrait) {
    .container {
        flex-direction: column;
        height: auto;
    }

    .control-sidebar {
        width: 100%;
        max-height: 35vh; /* 减少控制区域的最大高度 */
        border-right: none;
        border-bottom: 1px solid #f0f0f0;
        padding: 10px;
        gap: 5px;
    }

    .game-info {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 5px;
        justify-content: space-between;
    }

    .current-number,
    .timer,
    .level-info {
        flex: 1;
        min-width: 0; /* 允许元素变窄 */
        padding: 6px 8px;
    }

    .controls {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 8px;
        margin: 5px 0;
    }

    .level-selector {
        flex: 3;
    }

    button#start-btn {
        flex: 2;
    }

    .game-area {
        height: auto;
        min-height: 65vh; /* 增加游戏区域占比 */
    }
}

/* 特别针对小型设备的优化 */
@media (max-width: 600px), (max-height: 500px) {
    .control-sidebar {
        padding: 10px;
        gap: 8px;
    }

    h1 {
        font-size: 18px;
        margin-bottom: 10px;
    }

    .grid-container {
        gap: 6px;
    }

    .grid-container[style*='repeat(5, 1fr)'],
    .grid-container[style*='repeat(6, 1fr)'],
    .grid-container[style*='repeat(7, 1fr)'] {
        gap: 3px;
    }

    .grid-item {
        border-width: 1px;
        border-radius: 6px;
    }
}

/* 为不同尺寸的网格设置字体和间距 - 改进字体大小计算 */
.grid-container[style*='repeat(3, 1fr)'] .grid-item {
    font-size: min(8vw, 8vh, 40px);
}

.grid-container[style*='repeat(4, 1fr)'] .grid-item {
    font-size: min(6vw, 6vh, 32px);
}

.grid-container[style*='repeat(5, 1fr)'] .grid-item {
    font-size: min(5vw, 5vh, 28px);
}

.grid-container[style*='repeat(6, 1fr)'] .grid-item {
    font-size: min(4vw, 4vh, 24px);
}

.grid-container[style*='repeat(7, 1fr)'] .grid-item {
    font-size: min(3vw, 3vh, 20px);
}

/* 改进CSS min函数的使用，确保更好的兼容性 */
@supports (width: min(90vw, 90vh)) {
    .grid-container {
        width: 90%;
        max-width: min(90vw, 90vh);
    }

    .game-active .grid-container {
        max-width: min(95vw, 95vh);
    }

    @media (orientation: landscape) {
        .grid-container {
            max-width: min(90vh, calc(90vw - 220px));
        }

        .game-active .grid-container {
            max-width: min(95vh, calc(95vw - 220px));
        }
    }
}

/* 横屏小尺寸设备的特殊处理 */
@media (orientation: landscape) and (max-height: 500px) {
    .control-sidebar {
        width: 180px;
    }

    .grid-container {
        max-width: min(95vh, calc(95vw - 180px));
        gap: 5px;
    }
}

/* 竖屏小尺寸设备的特殊处理 */
@media (orientation: portrait) and (max-width: 400px) {
    .grid-container {
        width: 98%;
        max-width: 98vw;
        gap: 5px;
    }
}

/* 处理时间相关类在小屏幕上的显示 */
@media (max-width: 600px) {
    #time-limit-bar-container {
        height: 6px;
        margin: 5px 0;
    }

    .timer {
        padding: 8px 10px;
    }
}

/* 处理横屏小尺寸设备上的时间相关元素 */
@media (orientation: landscape) and (max-height: 500px) {
    #time-limit-bar-container {
        height: 5px;
        margin: 4px 0;
    }

    .timer {
        padding: 5px 8px;
    }
}

/* 针对小屏幕和横屏模式的优化 */
@media (max-width: 600px), (orientation: landscape) and (max-height: 600px) {
    .timer {
        padding: 6px 10px;
        font-size: 14px;
    }

    #time-limit-bar-container {
        height: 6px;
        margin-top: 3px;
    }
}

/* 移除未使用的关卡描述简介区域样式 */
.level-info-brief,
.level-name,
.detail-btn {
    display: none;
}

/* 关卡详情蒙层样式 */
.level-detail-modal {
    background-color: white;
    padding: 25px;
    border-radius: 15px;
    max-width: 90%;
    width: 550px;
    max-height: 90vh;
    overflow-y: auto;
    transform: scale(0.9);
    transition: transform 0.3s ease;
    box-shadow: 0 5px 30px rgba(0, 0, 0, 0.3);
    position: relative;
}

.modal-overlay.active .level-detail-modal {
    transform: scale(1);
}

.level-detail-content {
    padding: 0;
    max-height: none;
    overflow: visible;
    margin-bottom: 15px;
}

.level-detail-content h3 {
    margin-bottom: 12px;
    color: #9c27b0;
    font-size: 20px;
    border-bottom: 2px solid rgba(156, 39, 176, 0.2);
    padding-bottom: 8px;
}

.level-detail-content p {
    margin-bottom: 8px;
    line-height: 1.6;
    font-size: 15px;
}

.close-btn {
    background-color: #f5f5f5;
    color: #333;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 15px;
    transition: all 0.2s ease;
    margin-top: 5px;
    width: 100%;
}

.close-btn:hover {
    background-color: #e0e0e0;
}

/* 保留原有的关卡描述样式，但针对新的应用场景进行调整 */
#level-detail {
    background-color: white;
    width: 100%;
    font-size: 15px;
    line-height: 1.6;
}

.record-info {
    background-color: rgba(76, 175, 80, 0.1);
    padding: 10px 15px;
    border-radius: 6px;
    display: block;
    margin: 12px 0;
    color: #2e7d32;
    font-weight: 600;
}

.star-req {
    color: #7b1fa2;
    font-weight: 600;
    display: block;
    margin: 15px 0 10px 0;
    border-bottom: 1px dotted rgba(123, 31, 162, 0.3);
    padding-bottom: 5px;
    font-size: 16px;
}

/* 响应式调整 */
@media (max-width: 600px) {
    .level-detail-modal {
        width: 95%;
        padding: 20px;
    }

    .level-detail-content h3 {
        font-size: 18px;
    }

    .level-detail-content p {
        font-size: 14px;
    }

    .level-info-brief {
        padding: 10px;
    }

    .detail-btn {
        padding: 6px 10px;
        font-size: 12px;
    }
}

/* 隐藏未使用的关卡描述简介区域 */
.level-info-brief {
    display: none !important;
}

/* 信息按钮样式 */
.info-btn {
    background-color: #9c27b0;
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
    margin-left: 5px;
    flex-shrink: 0;
}

.info-btn:hover {
    transform: scale(1.1);
    background-color: #7b1fa2;
}

/* 在小屏幕和横屏模式下优化信息按钮 */
@media (max-width: 600px), (orientation: landscape) and (max-height: 500px) {
    .info-btn {
        width: 20px;
        height: 20px;
        font-size: 12px;
    }
}

/* 专为小屏幕设备优化（如iPhone SE等） */
@media (max-width: 380px) {
    .control-sidebar {
        padding: 8px;
        gap: 4px;
        max-height: 32vh;
    }

    h1 {
        font-size: 16px;
        margin-bottom: 5px;
    }

    .game-info {
        gap: 4px;
    }

    .current-number,
    .timer,
    .level-info {
        padding: 4px 6px;
        font-size: 11px;
    }

    .info-btn {
        width: 18px;
        height: 18px;
        font-size: 10px;
    }

    .level-selector label {
        font-size: 11px;
    }

    .level-selector select {
        padding: 4px 6px;
        font-size: 11px;
    }

    button#start-btn {
        padding: 6px 8px;
        font-size: 12px;
    }
}

/* 特别针对超小屏幕设备（低于320px宽度）*/
@media (max-width: 320px) {
    .control-sidebar {
        padding: 5px;
        gap: 3px;
        max-height: 30vh;
    }

    h1 {
        font-size: 14px;
        margin-bottom: 3px;
    }

    .current-number,
    .timer,
    .level-info {
        padding: 3px 5px;
        font-size: 10px;
    }
}
